package xin.clips.web.controller.gy;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import xin.clips.common.annotation.Log;
import xin.clips.common.enums.BusinessType;
import xin.clips.common.core.controller.BaseController;
import xin.clips.common.core.domain.AjaxResult;
import xin.clips.common.utils.poi.ExcelUtil;
import xin.clips.common.core.page.TableDataInfo;
import xin.clips.system.domain.gy.GyDeviceTime;
import xin.clips.system.service.gy.IGyDeviceTimeService;

/**
 * 设备运行时间Controller
 *
 * @author clips
 * @date 2023-01-13
 */
@Controller
@RequestMapping("/gy/time")
public class GyDeviceTimeController extends BaseController
{
    private String prefix = "gy/deviceTime";

    @Autowired
    private IGyDeviceTimeService gyDeviceTimeService;

    @RequiresPermissions("gy:time:view")
    @GetMapping()
    public String time()
    {
        return prefix + "/time";
    }

    /**
     * 查询设备运行时间列表
     */
    @RequiresPermissions("gy:time:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GyDeviceTime gyDeviceTime)
    {
        startPage();
        List<GyDeviceTime> list = gyDeviceTimeService.selectGyDeviceTimeList(gyDeviceTime);
        return getDataTable(list);
    }

    /**
     * 导出设备运行时间列表
     */
    @RequiresPermissions("gy:time:export")
    @Log(title = "设备运行时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GyDeviceTime gyDeviceTime)
    {
        List<GyDeviceTime> list = gyDeviceTimeService.selectGyDeviceTimeList(gyDeviceTime);
        ExcelUtil<GyDeviceTime> util = new ExcelUtil<GyDeviceTime>(GyDeviceTime.class);
        return util.exportExcel(list, "设备运行时间数据");
    }

    /**
     * 新增设备运行时间
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备运行时间
     */
    @RequiresPermissions("gy:time:add")
    @Log(title = "设备运行时间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GyDeviceTime gyDeviceTime)
    {
        return toAjax(gyDeviceTimeService.insertGyDeviceTime(gyDeviceTime));
    }

    /**
     * 修改设备运行时间
     */
    @RequiresPermissions("gy:time:edit")
    @GetMapping("/edit/{deviceId}")
    public String edit(@PathVariable("deviceId") Long deviceId, ModelMap mmap)
    {
        GyDeviceTime gyDeviceTime = gyDeviceTimeService.selectGyDeviceTimeByDeviceId(deviceId);
        mmap.put("gyDeviceTime", gyDeviceTime);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备运行时间
     */
    @RequiresPermissions("gy:time:edit")
    @Log(title = "设备运行时间", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GyDeviceTime gyDeviceTime)
    {
        return toAjax(gyDeviceTimeService.updateGyDeviceTime(gyDeviceTime));
    }

    /**
     * 删除设备运行时间
     */
    @RequiresPermissions("gy:time:remove")
    @Log(title = "设备运行时间", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gyDeviceTimeService.deleteGyDeviceTimeByDeviceIds(ids));
    }
}
